﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using AbstraXLocalTest;
using AbstraX.ClientInterfaces;
using AbstraX.XPathBuilder;
using TreeBuilderTest.Entities;
using System.IO;
using System.Collections.Generic;
using Microsoft.Practices.Unity;
using System.Diagnostics;
using MvvmTreeView;
using System.Linq;
using AbstraX;
namespace TreeBuilderTest.Services
{
    public class BaseSurrogate : IRootSurrogate
    {
        public IAbstraXExtension LoadExtention(IBase baseObject, ITreeNode treeNode)
        {
            return null;
        }
        public BaseSurrogate()
        {
            IoC.RegisterType<IRootSurrogate, BaseSurrogate>(new ContainerControlledLifetimeManager());
        }

        public void ExecuteWhere(IBase baseObject, string property, object value)
        {
            switch (baseObject.GetType().Name)
            {
                case "BaseSurrogate":
                    break;
                case "BaseTypeElement":
                    ((BaseTypeElement)baseObject).ExecuteWhere(property, value);
                    break;
                case "BasePropertyElement":
                    ((BasePropertyElement)baseObject).ExecuteWhere(property, value);
                    break;
                case "BasePropertyAttribute":
                    ((BasePropertyAttribute)baseObject).ExecuteWhere(property, value);
                    break;
                case "BaseMethodOperation":
                    ((BaseMethodOperation)baseObject).ExecuteWhere(property, value);
                    break;
                case "BaseConstructorOperation":
                    ((BaseConstructorOperation)baseObject).ExecuteWhere(property, value);
                    break;
                default:
                    Debugger.Break();
                    break;
            }
        }

        public void ExecuteWhere(IBase baseObject, Expression expression)
        {
        }

        public void ExecuteWhere(IBase baseObject, XPathAxisElement element)
        {
            var predicate = element.Predicates.First();

            var property = predicate.Left;
            var value = predicate.Right;

            switch (baseObject.GetType().Name)
            {
                case "BaseSurrogate":
                    break;
                case "BaseTypeElement":
                    ((BaseTypeElement)baseObject).ExecuteWhere(property, value);
                    break;
                case "BasePropertyElement":
                    ((BasePropertyElement)baseObject).ExecuteWhere(property, value);
                    break;
                case "BasePropertyAttribute":
                    ((BasePropertyAttribute)baseObject).ExecuteWhere(property, value);
                    break;
                case "BaseMethodOperation":
                    ((BaseMethodOperation)baseObject).ExecuteWhere(property, value);
                    break;
                case "BaseConstructorOperation":
                    ((BaseConstructorOperation)baseObject).ExecuteWhere(property, value);
                    break;
                default:
                    Debugger.Break();
                    break;
            }
        }

        public void ExecuteWhere(IBase baseObject, XPathAxisElement element, XPathAxisElement childrenElement)
        {
        }

        public void ClearPredicates(IBase baseObject)
        {
        }

        public System.Collections.Generic.IEnumerable<IElement> RootElements
        {
            get 
            {
                var baseType = new BaseTypeElement(typeof(ITreeView), this);

                return new List<IElement>() { baseType };
            }
        }

        public string URL
        {
            get 
            {
                return "AbstraX://Test/AssembliesRoot";
            }
        }

        public ProviderType ProviderType
        {
            get { throw new NotImplementedException(); }
        }

        public IType DataType
        {
            get { throw new NotImplementedException(); }
        }

        public void LoadChildren()
        {
            throw new NotImplementedException();
        }

        public event ChildrenLoadedHandler ChildrenLoaded;

        public string ID
        {
            get 
            {
                return this.MakeID("URL='" + this.URL + "'");
            }
        }

        public string ParentID
        {
            get { throw new NotImplementedException(); }
        }

        public string Name
        {
            get { throw new NotImplementedException(); }
        }

        public string Description
        {
            get { throw new NotImplementedException(); }
        }

        public string Documentation
        {
            get { throw new NotImplementedException(); }
        }

        public string ImageURL
        {
            get { throw new NotImplementedException(); }
        }

        public IBase Parent
        {
            get 
            {
                return null;
            }
        }

        public string FolderKeyPair
        {
            get { throw new NotImplementedException(); }
        }

        public System.ServiceModel.DomainServices.Client.DomainContext Context
        {
            get
            {
                throw new NotImplementedException();
            }
            set
            {
                throw new NotImplementedException();
            }
        }

        public void ExecuteGlobalWhere(IRoot root, XPathAxisElement element)
        {
        }

        public DefinitionKind Kind
        {
            get { throw new NotImplementedException(); }
        }

        public string ParentFieldName
        {
            get 
            {
                return "parentID";
            }
        }

        public bool HasChildren
        {
            get { throw new NotImplementedException(); }
        }

        public string DebugInfo
        {
            get { throw new NotImplementedException(); }
        }

        public float ChildOrdinal
        {
            get { throw new NotImplementedException(); }
        }
    }
}
